﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;

using Telerik.Web.UI;

using ConstructionBidOnline.Biz;
using ConstructionBidOnline.Common;


public partial class admin_ManageSettings : System.Web.UI.Page
{
    #region Constants

    //private const string PROP_DATASRC_FEATUREDJOBFEESSETTINGS = "__FEATUREDJOBFEESSETTINGS::FEATUREDJOBFEESSETTINGS";
    //private const string PROP_DATASRC_CONSULTANTSETTINGS = "__CONSULTANTSETTINGS::CONSULTANTSETTINGS";
    //private const string PROP_DATASRC_CONTRACTORSETTINGS = "__CONTRACTORSETTINGS::CONTRACTORSETTINGS";


    private const string PROP_DATASRC_CONTRACTJOBFEESSETTINGS = "__CONTRACTJOBFEESSETTINGS::CONTRACTJOBFEESSETTINGS";


    #endregion

    #region Public Properties

   public ContractJobFeesSettingsCollection DataSourceContractJobFeesSettings
    {
        get { return (SessionMgr.Session[PROP_DATASRC_CONTRACTJOBFEESSETTINGS] is ContractJobFeesSettingsCollection ? (ContractJobFeesSettingsCollection)SessionMgr.Session[PROP_DATASRC_CONTRACTJOBFEESSETTINGS] : (ContractJobFeesSettingsCollection)(SessionMgr.Session[PROP_DATASRC_CONTRACTJOBFEESSETTINGS] = new ContractJobFeesSettingsCollection())); }
        set { SessionMgr.Session[PROP_DATASRC_CONTRACTJOBFEESSETTINGS] = value; }
    }

    public ConsultantSettings Consultantsettingsobj;
    public ContractorSettings ContractorsettingsObj;
    public FeaturedFeesSettings FeaturedfeesSettingsObj;
    public ContractJobFeesSettings ContractJobFeesSettingsObj;



    #endregion    

    #region Public Method    

    #region cleartxtbox

    public void cleartxtbox()
    {
            comboSettingsfor.SelectedValue = "Select.";
            comboMembershipType.SelectedValue = "Select.";
            //combofeesrange.SelectedValue = "Select.";

        //Consultant TextBox
            txtConsultantMembershipfees.Text = string.Empty;
            txtConsultantTransactionfees.Text = string.Empty;
            txtConsultantVirtualassistant.Text = string.Empty;
            txtConsultantphotogallery.Text = string.Empty;
            txtConsultantVideoportfolio.Text = string.Empty;
       
        //Contractor TextBox
            txtContractorMembershipfees.Text = string.Empty;
            txtContractorBidpermonth.Text = string.Empty;
            txtContractorTransactionfees.Text = string.Empty;
            txtContractorBidselectionfees.Text = string.Empty;
            txtContractorNoOfkeywords.Text = string.Empty;
            //txtContractorfeaturedjobs.Text = string.Empty;
            txtContractorPhotogallery.Text = string.Empty;
            txtContractorVideoportfolio.Text = string.Empty;


        //Featured Job TexBox
            txtFeaturedJobfees.Text = string.Empty;

    }

    #endregion

    #endregion

    #region Event Handlers

    #region Page Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            
        }

        DataSourceContractJobFeesSettings = ContractJobFeesSettings.GetAllContractJobFeesSettings();
    }

    #endregion

    #region Button submit click

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
            Consultantsettingsobj = ConsultantSettings.GetConsultantSettingsByMembershipType(comboMembershipType.Text.Trim());
            ContractorsettingsObj = ContractorSettings.GetContractorSettingsByMembershipType(comboMembershipType.Text.Trim());
            FeaturedfeesSettingsObj = FeaturedFeesSettings.GetFeaturedFeesSettingsByID(1);
            if (comboSettingsfor.Text == "Consultant")
            {
                if (Consultantsettingsobj != null)
                {
                    UpdateData(UpdateDirection.UI_To_Obj);
                    ConsultantSettings.Update(Consultantsettingsobj);
                    lblmsgs.Visible = true;
                    lblmsgs.Text = "Your Record has been updated sucessfully";
                }
            }
            if (comboSettingsfor.Text == "Contractor")
            {
                if (ContractorsettingsObj != null)
                {
                    UpdateData(UpdateDirection.UI_To_Obj);
                    ContractorSettings.Update(ContractorsettingsObj);
                    lblmsgs.Visible = true;
                    lblmsgs.Text = "Your Record has been updated sucessfully";
                }
            }
            if (comboSettingsfor.Text == "Featured Job Fees")
            {
                if (FeaturedfeesSettingsObj != null)
                {
                    UpdateData(UpdateDirection.UI_To_Obj);
                    FeaturedFeesSettings.Update(FeaturedfeesSettingsObj);
                    lblmsgs.Visible = true;
                    lblmsgs.Text = "Your Record has been updated sucessfully";
                }
            }
            if (comboSettingsfor.Text == "Featured Directory Fees")
            {
                if (FeaturedfeesSettingsObj != null)
                {
                    UpdateData(UpdateDirection.UI_To_Obj);
                    FeaturedFeesSettings.Update(FeaturedfeesSettingsObj);
                    lblmsgs.Visible = true;
                    lblmsgs.Text = "Your Record has been updated sucessfully";
                } 
            }
            if (comboSettingsfor.Text == "Contract Job Fees")
            {
                string [] feesvalue = new string [5];
                feesvalue[0] = txtContractjobfees1.Text;
                feesvalue[1] = txtContractjobfees2.Text;
                feesvalue[2] = txtContractjobfees3.Text;
                feesvalue[3] = txtContractjobfees4.Text;
                feesvalue[4] = txtContractjobfees5.Text;

                for (int i = 0; i < DataSourceContractJobFeesSettings.Count; i++)
                {
                    ContractJobFeesSettings contractjfsObj = ContractJobFeesSettings.GetContractJobFeesSettingsByFeesRange(DataSourceContractJobFeesSettings[i].FeesRange);
                    contractjfsObj.ContractJobFees = decimal.Parse(feesvalue[i]);
                    ContractJobFeesSettings.Update(contractjfsObj);

                }
                    lblmsgs.Visible = true;
                    lblmsgs.Text = "Your Record has been updated sucessfully";

            }
            
            //cleartxtbox();
        }
    }

    #endregion

    #region Button cancel click

    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("DashBoard.aspx");
    }

    #endregion

    #region  comboSettingsfor_SelectedIndexChanged

    protected void comboSettingsfor_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        
        lblmsgs.Visible = false;
        if (comboSettingsfor.Text == "Consultant")
        {
            divMembershiptype.Visible = true;
            comboMembershipType.Items.Clear();
            comboMembershipType.Items.Add(new RadComboBoxItem("Select.", "Select."));
            comboMembershipType.Items.Add(new RadComboBoxItem("Commission Based", "Commission Based"));
            comboMembershipType.Items.Add(new RadComboBoxItem("Flat Monthly Fees", "Flat Monthly Fees"));
            
            
        }
        if (comboSettingsfor.Text == "Contractor")
        {
            divMembershiptype.Visible = true;
            comboMembershipType.Items.Clear();
            comboMembershipType.Items.Add(new RadComboBoxItem("Select.", "Select."));
            comboMembershipType.Items.Add(new RadComboBoxItem("Basic", "Basic"));
            comboMembershipType.Items.Add(new RadComboBoxItem("Small Contractor", "Small Contractor"));
            comboMembershipType.Items.Add(new RadComboBoxItem("Medium Contractor", "Medium Contractor"));
            comboMembershipType.Items.Add(new RadComboBoxItem("Bigger Contractor", "Bigger Contractor"));
            
        }
        if (comboSettingsfor.Text == "Featured Job Fees")
        {
            divMembershiptype.Visible = false;
            divforFeaturedJob.Visible = true;
            divforconsultantOnly.Visible = false;
            divforcontractorOnly.Visible = false;
            divContractJobFees.Visible = false;
            divfeatureddirectory.Visible = false;
            divConsultantcontractfees.Visible = false;

            txtFeaturedJobfees.Text = FeaturedFeesSettings.GetFeaturedFeesSettingsByID(1).FeaturedJobFees.ToString();
        }
        if (comboSettingsfor.Text == "Featured Directory Fees")
        {
            divfeatureddirectory.Visible = true;
            divMembershiptype.Visible = false;
            divforFeaturedJob.Visible = false;
            divforconsultantOnly.Visible = false;
            divforcontractorOnly.Visible = false;
            divContractJobFees.Visible = false;
            divConsultantcontractfees.Visible = false;

            txtfeatureddirectory.Text = FeaturedFeesSettings.GetFeaturedFeesSettingsByID(1).FeaturedDirectoryFees.ToString();
        }
        if (comboSettingsfor.Text == "Contract Job Fees")
        {

            divContractJobFees.Visible = true;

            txtContractjobfees1.Text = DataSourceContractJobFeesSettings[0].ContractJobFees.ToString();
            txtContractjobfees2.Text = DataSourceContractJobFeesSettings[1].ContractJobFees.ToString();
            txtContractjobfees3.Text = DataSourceContractJobFeesSettings[2].ContractJobFees.ToString();
            txtContractjobfees4.Text = DataSourceContractJobFeesSettings[3].ContractJobFees.ToString();
            txtContractjobfees5.Text = DataSourceContractJobFeesSettings[4].ContractJobFees.ToString();


            divMembershiptype.Visible = false;
            divforFeaturedJob.Visible = false;
            divforconsultantOnly.Visible = false;
            divforcontractorOnly.Visible = false;
            divfeatureddirectory.Visible = false;
            divConsultantcontractfees.Visible = false;
        }
    }

    #endregion

    #region comboMembershipType_SelectedIndexChanged

    protected void comboMembershipType_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        lblmsgs.Visible = false;
        Consultantsettingsobj = ConsultantSettings.GetConsultantSettingsByMembershipType(comboMembershipType.Text.Trim());
        ContractorsettingsObj = ContractorSettings.GetContractorSettingsByMembershipType(comboMembershipType.Text.Trim());
        
        if (Consultantsettingsobj != null && comboSettingsfor.Text == "Consultant")
        {
            divforconsultantOnly.Visible = true;
            divforFeaturedJob.Visible = false;
            divforcontractorOnly.Visible = false;
            divContractJobFees.Visible = false;
            divfeatureddirectory.Visible = false;
            if (comboMembershipType.Text == "Commission Based")
            {
                divConsultantcontractfees.Visible = true;
                txtConsultantcontractfees.Text = Consultantsettingsobj.ContractFees.ToString();
            }
            else
            {
                divConsultantcontractfees.Visible = false;
            }
            txtConsultantMembershipfees.Text = Consultantsettingsobj.MembershipFees.ToString();
            txtConsultantTransactionfees.Text = Consultantsettingsobj.TransactionFees.ToString();
            txtConsultantVirtualassistant.Text = Consultantsettingsobj.VirtualAssistant;
            txtConsultantKeywords.Text = Consultantsettingsobj.NumberOfKeywords.ToString();
            txtConsultantphotogallery.Text = Consultantsettingsobj.PhotoGallery;
            txtConsultantVideoportfolio.Text = Consultantsettingsobj.VideoProtfolio;
            
        }
        if (ContractorsettingsObj != null && comboSettingsfor.Text == "Contractor")
        {
            divforcontractorOnly.Visible = true;
            divforFeaturedJob.Visible = false;
            divforconsultantOnly.Visible = false;
            divContractJobFees.Visible = false;
            divfeatureddirectory.Visible = false;
            divConsultantcontractfees.Visible = false;

            txtContractorMembershipfees.Text = ContractorsettingsObj.MembershipFees.ToString();
            txtContractorBidpermonth.Text = ContractorsettingsObj.BidPerMonth;
            txtContractorTransactionfees.Text = ContractorsettingsObj.TransactionFees.ToString();
            txtContractorBidselectionfees.Text = ContractorsettingsObj.BidSelectionFees.ToString();
            txtContractorNoOfkeywords.Text = ContractorsettingsObj.NumberOfKeywords;
            txtContractorPhotogallery.Text = ContractorsettingsObj.PhotoGallery;
            txtContractorVideoportfolio.Text = ContractorsettingsObj.VideoProtfolio;
            chkboxContractorfeaturedjobs.Checked = ContractorsettingsObj.BidOnFeaturedJob;

            
        }
        

            
    }

    #endregion

    #endregion

    #region Privates

    #region UpdateData

    public void UpdateData(UpdateDirection updatedir)
    {

        if (updatedir == UpdateDirection.Obj_To_UI)
        {
            //View Elements





            //Edit Elements


        }
        else
        {
            Consultantsettingsobj = ConsultantSettings.GetConsultantSettingsByMembershipType(comboMembershipType.Text.Trim());
            ContractorsettingsObj = ContractorSettings.GetContractorSettingsByMembershipType(comboMembershipType.Text.Trim());
            FeaturedfeesSettingsObj = FeaturedFeesSettings.GetFeaturedFeesSettingsByID(1);

            #region DataBase entry for "CONSULTANT SETTINGS"
            //DataBase entry for "CONSULTANT"
            if (comboSettingsfor.Text == "Consultant")
            {
                if (Consultantsettingsobj != null)
                {
                    Consultantsettingsobj.MembershipFees = Convert.ToDecimal(txtConsultantMembershipfees.Text);
                    if (comboMembershipType.Text == "Commission Based")
                    {
                        Consultantsettingsobj.ContractFees = Convert.ToDecimal(txtConsultantcontractfees.Text);
                    }
                    else
                    {
                        Consultantsettingsobj.ContractFees = 0;
                    }
                    Consultantsettingsobj.TransactionFees = Convert.ToDecimal(txtConsultantTransactionfees.Text);
                    Consultantsettingsobj.NumberOfKeywords = Int32.Parse(txtConsultantKeywords.Text);
                    Consultantsettingsobj.VirtualAssistant = txtConsultantVirtualassistant.Text.Trim();
                    Consultantsettingsobj.PhotoGallery = txtConsultantphotogallery.Text.Trim();
                    Consultantsettingsobj.VideoProtfolio = txtConsultantVideoportfolio.Text.Trim();
                }
            }
            #endregion

            #region DataBase entry for "CONTRACTOR SETTINGS"
            //DataBase entry for "CONTRACTOR"
            if (comboSettingsfor.Text == "Contractor")
            {
                if (ContractorsettingsObj != null)
                {
                    ContractorsettingsObj.MembershipFees = Convert.ToDecimal(txtContractorMembershipfees.Text);
                    ContractorsettingsObj.BidPerMonth = txtContractorBidpermonth.Text.Trim();
                    ContractorsettingsObj.TransactionFees = Convert.ToDecimal(txtContractorTransactionfees.Text);
                    ContractorsettingsObj.BidSelectionFees = Convert.ToDecimal(txtContractorBidselectionfees.Text);
                    ContractorsettingsObj.NumberOfKeywords = txtContractorNoOfkeywords.Text.Trim();
                    ContractorsettingsObj.PhotoGallery = txtContractorPhotogallery.Text.Trim();
                    ContractorsettingsObj.VideoProtfolio = txtContractorVideoportfolio.Text.Trim();
                    ContractorsettingsObj.BidOnFeaturedJob = chkboxContractorfeaturedjobs.Checked;
                }
            }
            #endregion

            #region Database entry for "FEATURED JOB SETTINGS"
            //Database entry for Featured Job Settings
            if (comboSettingsfor.Text == "Featured Job Fees")
            {
                if (FeaturedfeesSettingsObj != null)
                {
                    FeaturedfeesSettingsObj.FeaturedJobFees = Convert.ToDecimal(txtFeaturedJobfees.Text.Trim());
                }
            }

            #endregion

            


        }


    }

    #endregion

    #endregion
    
}
